<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="ISO-8859-1">
    <title>书籍增删查改管理系统</title>





    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">



</head>
<body>

<div class="container my-2">
    <h1>书籍增删查改管理系统</h1>


    <form class="form-inline" th:action="@{/books/search}" method="post">
        <div class="form-group mb-2">
            <a th:href = "@{/showNewBookForm}" class="btn btn-primary btn-sm mb-3"> 添加书籍 </a>
        </div>
        <div class="form-group mx-sm-3 mb-2">
            <input type="text" class="form-control" name="author" placeholder="作者">
        </div>
        <button type="submit" class="btn btn-primary mb-2">查询</button>
    </form>
    <table border="1" class="table table-striped table-responsive-md">
        <!--表头-->
        <thead class="thead-light">
            <tr>
                <th><a th:href="@{'/page/' + ${currentPage} + '?sortField=id&sortDir=' + ${reverseSortDir}}">id</a></th>
                <th><a th:href="@{'/page/' + ${currentPage} + '?sortField=name&sortDir=' + ${reverseSortDir}}">书名</a></th>
                <th><a th:href="@{'/page/' + ${currentPage} + '?sortField=author&sortDir=' + ${reverseSortDir}}">作者</a></th>
                <th><a th:href="@{'/page/' + ${currentPage} + '?sortField=publisher&sortDir=' + ${reverseSortDir}}">出版社</a></th>
                <th><a th:href="@{'/page/' + ${currentPage} + '?sortField=bookNumber&sortDir=' + ${reverseSortDir}}">书籍编号</a></th>
                <th><a th:href="@{'/page/' + ${currentPage} + '?sortField=bookType&sortDir=' + ${reverseSortDir}}">书籍种类</a></th>
                <th><a th:href="@{'/page/' + ${currentPage} + '?sortField=price&sortDir=' + ${reverseSortDir}}">销售价格</a></th>
                <th>操作</th>
            </tr>
        </thead>

        <!--表格.  th:each循环遍历-->
        <tbody>
        <tr th:each="book : ${listBook}">
            <td th:text="${book.id}"></td>
            <td th:text="${book.name}"></td>
            <td th:text="${book.author}"></td>
            <td th:text="${book.publisher}"></td>
            <td th:text="${book.bookNumber}"></td>
            <td th:text="${book.bookType}"></td>
            <td th:text="${book.price}"></td>
            <td>
                <a th:href="@{/updateBook/{id}(id=${book.id})}" class="btn btn-primary">修改</a>
                <a th:href="@{/deleteBook/{id}(id=${book.id})}" class="btn btn-danger">删除</a>
            </td>

        </tr>
        </tbody>

    </table>

    <div th:if = "${totalPages > 1}">
        <div class = "row col-sm-10" >
            <div class = "col-sm-3">
                Total Rows: [[${totalItems}]]
            </div>

            <div class="pagination justify-content-end" >
					<span th:each="i: ${#numbers.sequence(1, totalPages)}" class="page-item">

						<a th:if="${currentPage != i}" th:href="@{'/page/' + ${i}+ '?sortField=' + ${sortField} + '&sortDir=' + ${sortDir}}" class="page-link">[[${i}]]</a>
						<span th:unless="${currentPage != i}" class="page-link">[[${i}]]</span>  &nbsp;
                        &nbsp;
					</span>
            </div>

            <div >
                <a th:if="${currentPage < totalPages}" th:href="@{'/page/' + ${currentPage + 1}+ '?sortField=' + ${sortField} + '&sortDir=' + ${sortDir}}" class="page-link">下一页</a>
                <span th:unless="${currentPage < totalPages}" class="page-link">下一页</span>
            </div>

            <div >
                <a th:if="${currentPage < totalPages}" th:href="@{'/page/' + ${totalPages}+ '?sortField=' + ${sortField} + '&sortDir=' + ${sortDir}}" class="page-link">最后一页</a>
                <span th:unless="${currentPage < totalPages}" class="page-link">最后一页</span>
            </div>

        </div>

    </div>




</div>



</body>
</html>